library(tidyverse)
## ── Attaching packages ────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1     ✓ purrr   0.3.3
## ✓ tibble  2.1.3     ✓ dplyr   0.8.3
## ✓ tidyr   1.0.0     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.4.0
## ── Conflicts ───────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(psych)
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(patchwork)
library(reshape2)
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(reticulate)
reticulate::use_python("/Users/catherinewalsh/miniconda3")

load('data/behav.RData')
load('data/split_groups_info.RData')
load('data/ISC_data.RData')

se <- function(x) {
  sd(x,na.rm=TRUE)/sqrt(length(x[!is.na(x)])) 
}

Temporal ISC

Want to look at which regions show a load effect.

load_effect_LOO <- fisherz(high_correct_ISC_LOO) - fisherz(low_correct_ISC_LOO)

load_effect_LOO[load_effect_LOO == -Inf] <- NA
load_effect_LOO[load_effect_LOO == Inf] <- NA

LOO_results <- data.frame(t=matrix(nrow=297),p=matrix(nrow=297), sig_05=matrix(nrow=297), sig_corrected=matrix(nrow=297))
# one sample t test against 0 

for (region in seq.int(1,297)){
  temp <- t.test(load_effect_LOO[,region])
  LOO_results$t[region] <- temp$statistic
  LOO_results$p[region] <- temp$p.value
  if (temp$p.value < 0.05){
    LOO_results$sig_05[region] <- TRUE
  } else {
    LOO_results$sig_05[region] <- FALSE
  }
  if (temp$p.value < 0.05/297){
    LOO_results$sig_corrected[region] <- TRUE
  } else {
    LOO_results$sig_corrected[region] <- FALSE
  }
}

print("Regions that show a load effect (corrected for multiple comparisons): ")
## [1] "Regions that show a load effect (corrected for multiple comparisons): "
labels[LOO_results$sig_corrected,]
##  [1] "7Networks_LH_Vis_5"                "7Networks_LH_Vis_11"              
##  [3] "7Networks_LH_Vis_18"               "7Networks_LH_Vis_21"              
##  [5] "7Networks_LH_Vis_22"               "7Networks_LH_Vis_23"              
##  [7] "7Networks_LH_Vis_27"               "7Networks_LH_DorsAttn_Post_5"     
##  [9] "7Networks_LH_DorsAttn_Post_7"      "7Networks_LH_DorsAttn_Post_9"     
## [11] "7Networks_LH_DorsAttn_Post_11"     "7Networks_LH_DorsAttn_Post_12"    
## [13] "7Networks_LH_DorsAttn_Post_13"     "7Networks_LH_DorsAttn_FEF_3"      
## [15] "7Networks_LH_SalVentAttn_FrOper_9" "7Networks_LH_SalVentAttn_PFCl_1"  
## [17] "7Networks_LH_SalVentAttn_Med_7"    "7Networks_LH_Cont_Par_2"          
## [19] "7Networks_LH_Cont_Par_6"           "7Networks_LH_Cont_PFCl_2"         
## [21] "7Networks_LH_Cont_PFCl_4"          "7Networks_LH_Cont_PFCl_7"         
## [23] "7Networks_LH_Cont_PFCl_8"          "7Networks_LH_Cont_PFCmp_1"        
## [25] "7Networks_LH_Default_Temp_1"       "7Networks_LH_Default_Temp_12"     
## [27] "7Networks_LH_Default_Temp_15"      "7Networks_LH_Default_PFC_1"       
## [29] "7Networks_LH_Default_PFC_2"        "7Networks_LH_Default_PFC_5"       
## [31] "7Networks_LH_Default_PFC_9"        "7Networks_LH_Default_PCC_6"       
## [33] "7Networks_LH_Default_PCC_7"        "7Networks_RH_Vis_6"               
## [35] "7Networks_RH_Vis_11"               "7Networks_RH_Vis_15"              
## [37] "7Networks_RH_Vis_19"               "7Networks_RH_Vis_22"              
## [39] "7Networks_RH_Vis_26"               "7Networks_RH_DorsAttn_Post_4"     
## [41] "7Networks_RH_DorsAttn_Post_9"      "7Networks_RH_DorsAttn_Post_11"    
## [43] "7Networks_RH_DorsAttn_Post_12"     "7Networks_RH_DorsAttn_Post_15"    
## [45] "7Networks_RH_DorsAttn_Post_16"     "7Networks_RH_DorsAttn_Post_17"    
## [47] "7Networks_RH_DorsAttn_Post_18"     "7Networks_RH_DorsAttn_FEF_1"      
## [49] "7Networks_RH_DorsAttn_FEF_2"       "7Networks_RH_SalVentAttn_FrOper_6"
## [51] "7Networks_RH_SalVentAttn_FrOper_7" "7Networks_RH_SalVentAttn_FrOper_8"
## [53] "7Networks_RH_SalVentAttn_Med_2"    "7Networks_RH_Cont_Par_2"          
## [55] "7Networks_RH_Cont_Par_4"           "7Networks_RH_Cont_Par_5"          
## [57] "7Networks_RH_Cont_Par_6"           "7Networks_RH_Cont_PFCl_8"         
## [59] "7Networks_RH_Cont_Cing_1"          "7Networks_RH_Default_Par_4"       
## [61] "7Networks_RH_Default_Temp_1"       "7Networks_RH_Default_Temp_2"      
## [63] "7Networks_RH_Default_PFCm_3"       "7Networks_RH_Default_PFCm_9"
sig_LOO <- load_effect_LOO[,LOO_results$sig_corrected]

visual <- sig_LOO[,c(1:7,34:39)]
dorsal_attn <- sig_LOO[,c(8:14,40:49)]
ventral_attn <- sig_LOO[,c(15:17,50:53)]
FPCN <- sig_LOO[,c(18:23,54:59)]
DMN <- sig_LOO[,c(25:33,61:64)]

network_avg_LOO <- data.frame(visual=rowMeans(visual), DAN = rowMeans(dorsal_attn), VAN = rowMeans(ventral_attn), FPCN = rowMeans(FPCN), DMN = rowMeans(DMN))

LOO - all subjects

data_for_plot <- data.frame(network_avg_LOO, PTID = constructs_fMRI$PTID, BPRS = p200_clinical_zscores$BPRS_TOT[p200_clinical_zscores$PTID %in% constructs_fMRI$PTID], L3_acc = p200_data$XDFR_MRI_ACC_L3[p200_data$PTID %in% constructs_fMRI$PTID], omnibus_span = constructs_fMRI$omnibus_span_no_DFR_MRI)

data_for_plot$BPRS[data_for_plot$BPRS > 4] <- NA

plot_list <- list()

for (network in seq.int(1,5)){
  for (measure in seq.int(7,9)){
    plot_list[[colnames(data_for_plot)[network]]][[colnames(data_for_plot)[measure]]] <- ggplot(data=data_for_plot, aes_string(x= colnames(data_for_plot)[measure], y = colnames(data_for_plot)[network]))+
      geom_point()+
      stat_smooth(method="lm")+
      theme_classic()
  }
}

DAN/L3 acc, trend with BPRS DMN with L3 acc

plot_list[["visual"]][["omnibus_span"]]+ plot_list[["visual"]][["L3_acc"]] + plot_list[["visual"]][["BPRS"]] +
  plot_layout(ncol=2)+
  plot_annotation("Average temporal ISC in Visual ROIs")
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).

for (measure in seq.int(7,9)){
  print(colnames(data_for_plot)[measure])
  print(cor.test(data_for_plot$visual, data_for_plot[,measure]))
}
## [1] "BPRS"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$visual and data_for_plot[, measure]
## t = -0.77458, df = 167, p-value = 0.4397
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.20890473  0.09195905
## sample estimates:
##         cor 
## -0.05983157 
## 
## [1] "L3_acc"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$visual and data_for_plot[, measure]
## t = 1.7426, df = 168, p-value = 0.08323
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.01762173  0.27818115
## sample estimates:
##       cor 
## 0.1332459 
## 
## [1] "omnibus_span"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$visual and data_for_plot[, measure]
## t = 0.13039, df = 168, p-value = 0.8964
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1406681  0.1603306
## sample estimates:
##        cor 
## 0.01005913
plot_list[["FPCN"]][["omnibus_span"]]+ plot_list[["FPCN"]][["L3_acc"]] + plot_list[["FPCN"]][["BPRS"]] +
  plot_layout(ncol=2)+
  plot_annotation("Average temporal ISC in FPCN ROIs")
## Warning: Removed 1 rows containing non-finite values (stat_smooth).

## Warning: Removed 1 rows containing missing values (geom_point).

for (measure in seq.int(7,9)){
  print(colnames(data_for_plot)[measure])
  print(cor.test(data_for_plot$FPCN, data_for_plot[,measure]))
}
## [1] "BPRS"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$FPCN and data_for_plot[, measure]
## t = -1.7987, df = 167, p-value = 0.07387
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.28293088  0.01337949
## sample estimates:
##       cor 
## -0.137859 
## 
## [1] "L3_acc"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$FPCN and data_for_plot[, measure]
## t = 1.1208, df = 168, p-value = 0.264
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.06521038  0.23363422
## sample estimates:
##        cor 
## 0.08614944 
## 
## [1] "omnibus_span"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$FPCN and data_for_plot[, measure]
## t = 1.011, df = 168, p-value = 0.3135
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.07360969  0.22563932
## sample estimates:
##        cor 
## 0.07776616
plot_list[["DMN"]][["omnibus_span"]]+ plot_list[["DMN"]][["L3_acc"]] + plot_list[["DMN"]][["BPRS"]] +
  plot_layout(ncol=2)+
  plot_annotation("Average temporal ISC in DMN ROIs")
## Warning: Removed 1 rows containing non-finite values (stat_smooth).

## Warning: Removed 1 rows containing missing values (geom_point).

for (measure in seq.int(7,9)){
  print(colnames(data_for_plot)[measure])
  print(cor.test(data_for_plot$DMN, data_for_plot[,measure]))
}
## [1] "BPRS"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$DMN and data_for_plot[, measure]
## t = -0.090326, df = 167, p-value = 0.9281
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1577830  0.1441227
## sample estimates:
##          cor 
## -0.006989431 
## 
## [1] "L3_acc"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$DMN and data_for_plot[, measure]
## t = 2.3467, df = 168, p-value = 0.02011
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.02840307 0.32008683
## sample estimates:
##       cor 
## 0.1781557 
## 
## [1] "omnibus_span"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$DMN and data_for_plot[, measure]
## t = 1.0827, df = 168, p-value = 0.2805
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.06812651  0.23086306
## sample estimates:
##       cor 
## 0.0832413
plot_list[["DAN"]][["omnibus_span"]]+ plot_list[["DAN"]][["L3_acc"]] + plot_list[["DAN"]][["BPRS"]] +
  plot_layout(ncol=2)+
  plot_annotation("Average temporal ISC in DAN ROIs")
## Warning: Removed 1 rows containing non-finite values (stat_smooth).

## Warning: Removed 1 rows containing missing values (geom_point).

for (measure in seq.int(7,9)){
  print(colnames(data_for_plot)[measure])
  print(cor.test(data_for_plot$DAN, data_for_plot[,measure]))
}
## [1] "BPRS"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$DAN and data_for_plot[, measure]
## t = -1.8703, df = 167, p-value = 0.06319
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.287971161  0.007892701
## sample estimates:
##       cor 
## -0.143238 
## 
## [1] "L3_acc"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$DAN and data_for_plot[, measure]
## t = 2.9392, df = 168, p-value = 0.003754
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.07306722 0.35969089
## sample estimates:
##       cor 
## 0.2211494 
## 
## [1] "omnibus_span"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$DAN and data_for_plot[, measure]
## t = 1.5391, df = 168, p-value = 0.1257
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.03318511  0.26375122
## sample estimates:
##       cor 
## 0.1179181
plot_list[["VAN"]][["omnibus_span"]]+ plot_list[["VAN"]][["L3_acc"]] + plot_list[["VAN"]][["BPRS"]] +
  plot_layout(ncol=2)+
  plot_annotation("Average temporal ISC in VAN ROIs")
## Warning: Removed 1 rows containing non-finite values (stat_smooth).

## Warning: Removed 1 rows containing missing values (geom_point).

for (measure in seq.int(7,9)){
  print(colnames(data_for_plot)[measure])
  print(cor.test(data_for_plot$VAN, data_for_plot[,measure]))
}
## [1] "BPRS"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$VAN and data_for_plot[, measure]
## t = -1.6153, df = 167, p-value = 0.1081
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.26993505  0.02744475
## sample estimates:
##        cor 
## -0.1240291 
## 
## [1] "L3_acc"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$VAN and data_for_plot[, measure]
## t = 0.20117, df = 168, p-value = 0.8408
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1353115  0.1656461
## sample estimates:
##        cor 
## 0.01551879 
## 
## [1] "omnibus_span"
## 
##  Pearson's product-moment correlation
## 
## data:  data_for_plot$VAN and data_for_plot[, measure]
## t = 1.464, df = 168, p-value = 0.1451
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.03893637  0.25838497
## sample estimates:
##       cor 
## 0.1122356

Pairwise

high_pairwise_sig <- high_correct_ISC_pairwise[,,LOO_results$sig_corrected]
low_pairwise_sig <- low_correct_ISC_pairwise[,,LOO_results$sig_corrected]
load_effect_pairwise <- high_pairwise_sig - low_pairwise_sig

visual_pairwise_L3 <- high_pairwise_sig[,,c(1:7,34:39)]
dorsal_attn_pairwise_L3 <- high_pairwise_sig[,,c(8:14,40:49)]
ventral_attn_pairwise_L3 <- high_pairwise_sig[,,c(15:17,50:53)]
FPCN_pairwise_L3 <- high_pairwise_sig[,,c(18:23,54:59)]
DMN_pairwise_L3 <- high_pairwise_sig[,,c(25:33,61:64)]

network_pairwise_high_load <- list(visual = apply(visual_pairwise_L3, c(1,2), mean), FPCN = apply(FPCN_pairwise_L3, c(1,2), mean), DMN = apply(DMN_pairwise_L3, c(1,2), mean), DAN = apply(dorsal_attn_pairwise_L3, c(1,2), mean), VAN = apply(ventral_attn_pairwise_L3, c(1,2), mean))

visual_pairwise <- load_effect_pairwise[,,c(1:7,34:39)]
dorsal_attn_pairwise <- load_effect_pairwise[,,c(8:14,40:49)]
ventral_attn_pairwise <- load_effect_pairwise[,,c(15:17,50:53)]
FPCN_pairwise <- load_effect_pairwise[,,c(18:23,54:59)]
DMN_pairwise <- load_effect_pairwise[,,c(25:33,61:64)]

network_pairwise <- list(visual = apply(visual_pairwise, c(1,2), mean), FPCN = apply(FPCN_pairwise, c(1,2), mean), 
                         DMN = apply(DMN_pairwise, c(1,2), mean), DAN = apply(dorsal_attn_pairwise, c(1,2), mean), 
                         VAN = apply(ventral_attn_pairwise, c(1,2), mean))
# reorder based on span 
span_order <- order(constructs_fMRI$omnibus_span_no_DFR_MRI)

network_pairwise_span_ordered_high_load <- list()
network_pairwise_span_ordered <- list()
for (network in seq.int(1,5)){
  network_pairwise_span_ordered_high_load[[network]] <- network_pairwise_high_load[[network]][span_order, span_order]
  network_pairwise_span_ordered[[network]] <- network_pairwise[[network]][span_order, span_order]
}
network_graphs_high_load <- list()

for (network in seq.int(1,5)){
  data <- data.frame(network_pairwise_span_ordered_high_load[[network]][,])
  rownames(data) <- c(1:170)
  colnames(data) <- c(1:170)
  data %>%
    
    # Data wrangling
    as_tibble() %>%
    rowid_to_column(var="X") %>%
    gather(key="Y", value="Z", -1) %>% 
    
    # Change Y to numeric
    mutate(Y=as.numeric(gsub("V","",Y))) -> mutated_data
  # 
  ggplot(data=mutated_data,aes(X, Y, fill= Z)) +
    geom_tile() +
    scale_y_continuous(breaks = c(0,50,100,150),labels=c(0,50,100,150))+
    geom_hline(yintercept=57,color="black")+
    geom_hline(yintercept=114,color="black")+
    geom_vline(xintercept=57,color="black")+
    geom_vline(xintercept=114,color="black")+
    scale_fill_gradient2()+
    theme(aspect=1)+
    labs(fill="ISC")+
    ggtitle(paste("network:",names(network_pairwise)[network]))-> network_graphs_high_load[[network]]
}
network_graphs_load_effect <- list()

for (network in seq.int(1,5)){
  data <- data.frame(network_pairwise_span_ordered[[network]][,])
  rownames(data) <- c(1:170)
  colnames(data) <- c(1:170)
  data %>%
    
    # Data wrangling
    as_tibble() %>%
    rowid_to_column(var="X") %>%
    gather(key="Y", value="Z", -1) %>% 
    
    # Change Y to numeric
    mutate(Y=as.numeric(gsub("V","",Y))) -> mutated_data
  # 
  ggplot(data=mutated_data,aes(X, Y, fill= Z)) +
    geom_tile() +
    scale_y_continuous(breaks = c(0,50,100,150),labels=c(0,50,100,150))+
    geom_hline(yintercept=57,color="black")+
    geom_hline(yintercept=114,color="black")+
    geom_vline(xintercept=57,color="black")+
    geom_vline(xintercept=114,color="black")+
    scale_fill_gradient2()+
    theme(aspect=1)+
    labs(fill="Load Effect")+
    ggtitle(paste("network:",names(network_pairwise)[network]))-> network_graphs_load_effect[[network]]
}

High Load

Visualize pairwise comparisons

network_graphs_high_load[[1]] 

network_graphs_high_load[[2]] 

network_graphs_high_load[[3]] 

network_graphs_high_load[[4]] 

network_graphs_high_load[[5]] 

t_test_res = data.frame(matrix(nrow=5,ncol=2)) 
colnames(t_test_res) <- c("t value","p value")
cols <- c("low_within","low_across","med_within","med_across","high_within","high_across")

group_means <- data.frame(matrix(nrow=5,ncol=6))
colnames(group_means) <- cols

group_se <- data.frame(matrix(nrow=5,ncol=6))
colnames(group_se) <- cols

avg_over_groups<- list(mean=data.frame(within = matrix(nrow=5,ncol=1),across = matrix(nrow=5,ncol=1)),
                       se=data.frame(within = matrix(nrow=5,ncol=1),across = matrix(nrow=5,ncol=1)))

split_list <- list()
all_ISC_list_high_load <- list()

for (network in seq.int(1:5)){
  
  # define dataframes 
  comps <- data.frame(within = matrix(nrow=170,ncol=1),across = matrix(nrow=170,ncol=1))
  
  split_by_groups <- data.frame(matrix(nrow=56,ncol=6))
  colnames(split_by_groups) <- cols
  
  # loop over all subjects and make comparisons
  for (suj in c(1:56, 58:113, 115:170)){
    if (suj < 57){
      comps$within[suj] <- mean(network_pairwise_span_ordered_high_load[[network]][1:56,suj],na.rm=TRUE)
      comps$across[suj] <- mean(network_pairwise_span_ordered_high_load[[network]][c(58:113,115:170),suj],na.rm=TRUE)
    }else if (suj > 57 & suj < 114){ 
      comps$within[suj] <- mean(network_pairwise_span_ordered_high_load[[network]][58:113,suj],na.rm=TRUE)
      comps$across[suj] <- mean(network_pairwise_span_ordered_high_load[[network]][c(1:56,115:170),suj],na.rm=TRUE)
    }else if (suj > 114){ 
      comps$within[suj] <- mean(network_pairwise_span_ordered_high_load[[network]][115:170,suj],na.rm=TRUE)
      comps$across[suj] <- mean(network_pairwise_span_ordered_high_load[[network]][c(1:56,58:113),suj],na.rm=TRUE)}
    
  }
  all_ISC_list_high_load[[names(network_pairwise)[network]]] <- comps 
  
  # average over groups 
  avg_over_groups[["mean"]]$within[network] <- mean(comps$within, na.rm=TRUE)
  avg_over_groups[["mean"]]$across[network] <- mean(comps$across, na.rm=TRUE)
  avg_over_groups[["se"]]$within[network] <- se(comps$within)
  avg_over_groups[["se"]]$across[network] <- se(comps$across)
  
  avg_over_groups[["mean"]]$difference[network] <- avg_over_groups[["mean"]]$within[network] - avg_over_groups[["mean"]]$across[network]
  avg_over_groups[["se"]]$difference[network] <- se(comps$within - comps$across)
  
  # split by groups 
  split_by_groups$low_across <- comps$across[1:56]
  split_by_groups$low_within <- comps$within[1:56]
  
  split_by_groups$med_across <- comps$across[58:113]
  split_by_groups$med_within <- comps$within[58:113]
  
  split_by_groups$high_across <- comps$across[115:170]
  split_by_groups$high_within <- comps$within[115:170]
  
  split_list[[names(network_pairwise)[network]]] <- split_by_groups
  
  group_means[network,] <- colMeans(split_by_groups)
  for (group in seq.int(1,6)){
    group_se[network,group] <- se(split_by_groups[,group])
  }
  temp2 <- t.test(comps$within,comps$across,paired=TRUE,var.equal = FALSE)
  t_test_res[network,] <- c(temp2$statistic,temp2$p.value)
  
}

rownames(t_test_res) <- names(network_pairwise) 
print(t_test_res)
##           t value      p value
## visual -5.0995924 9.155685e-07
## FPCN    1.7065772 8.975943e-02
## DMN     2.4082910 1.711611e-02
## DAN    -3.1638297 1.850336e-03
## VAN    -0.3083997 7.581626e-01
bar_list <- list()
bar_plot_data <- data.frame(matrix(nrow = 30, ncol=7))
colnames(bar_plot_data) <- c("mean", "se", "network_name", "comparison", "WMC", "err_min", "err_max")
comparison_list <- c("within", "across")
WMC_list <- c("low", "med", "high")
row_count=1
#row for mean, se, network, comparison, WMC
for (network in seq.int(1,5)){
  for (WMC in seq.int(1,3)){
    for (comparison in seq.int(1,2)){
      col_to_look <- ((WMC-1)*2+1) + (comparison-1)
      bar_plot_data$mean[row_count] <- mean(split_list[[network]][,col_to_look])  
      bar_plot_data$se[row_count] <- group_se[network,col_to_look]
      bar_plot_data$err_min[row_count] <- bar_plot_data$mean[row_count] - bar_plot_data$se[row_count]
      bar_plot_data$err_max[row_count] <- bar_plot_data$mean[row_count] + bar_plot_data$se[row_count]
      bar_plot_data$network_name[row_count] <- names(network_pairwise)[network]
      bar_plot_data$comparison[row_count] <- comparison_list[comparison] 
      bar_plot_data$WMC[row_count] <- WMC_list[WMC]
      row_count = row_count+1
    }
  }
  
  bar_plot_data$comparison <- as.factor(bar_plot_data$comparison)
  bar_plot_data$WMC <- factor(bar_plot_data$WMC, levels=c("low", "med", "high"))
  
  bar_plot_data %>%
    filter(network_name == names(network_pairwise)[network]) %>%
    ggplot(aes(x=WMC, y= mean, fill=comparison))+
    geom_bar(stat="identity", position="dodge")+
    geom_errorbar(aes(ymin=err_min, ymax=err_max), position=position_dodge(0.9), width=0.2)+
    ylab("Mean ISC")+
    ggtitle(paste0("network:", names(network_pairwise)[network])) -> bar_list[[names(network_pairwise)[network]]]
  
  
}

Average over subjects

(bar_list[["visual"]] + bar_list[["FPCN"]]) +
  plot_layout(guides="collect")

(bar_list[["DMN"]]+ bar_list[["DAN"]])+
  plot_layout(guides="collect")

bar_list[["VAN"]] 

#### Compare to behavior

VAN - both to acc; trend to span within DAN - both to acc; trend to span within DMN - both to acc; across to span FPCN: across to acc; within to span visual: both to acc

for (network in seq.int(1,5)){
  data_to_plot <- data.frame(constructs_fMRI[span_order, c(1,7)], all_ISC_list_high_load[[network]])
  data_to_plot <- merge(data_to_plot, p200_clinical_zscores[,c(1,2,8)], by="PTID")
  data_to_plot <- merge(data_to_plot, p200_data[,c(1,7)], by="PTID")
  data_to_plot$BPRS_TOT[data_to_plot$BPRS_TOT > 4] <- NA
  
  
  print(names(network_pairwise)[network])
  
  print(ggplot(data = data_to_plot)+
          geom_point(aes(x=omnibus_span_no_DFR_MRI,y=within), fill="black")+
          geom_smooth(aes(x=omnibus_span_no_DFR_MRI,y=within), method="lm", color="black")+
          geom_point(aes(x=omnibus_span_no_DFR_MRI,y=across), color="red")+
          geom_smooth(aes(x=omnibus_span_no_DFR_MRI,y=across), method="lm", color="red")+
          ylab("ISC")+
          ggtitle(paste0("network: "), names(network_pairwise)[network]))
  
  print(cor.test(data_to_plot$omnibus_span_no_DFR_MRI, data_to_plot$within))
  print(cor.test(data_to_plot$omnibus_span_no_DFR_MRI, data_to_plot$across))
  
  
  print(ggplot(data = data_to_plot)+
          geom_point(aes(x=BPRS_TOT,y=within), fill="black")+
          geom_smooth(aes(x=BPRS_TOT,y=within), method="lm", color="black")+
          geom_point(aes(x=BPRS_TOT,y=across), color="red")+
          geom_smooth(aes(x=BPRS_TOT,y=across), method="lm", color="red")+
          ylab("ISC")+
          ggtitle(paste0("network: "), names(network_pairwise)[network]))
  
  print(cor.test(data_to_plot$BPRS_TOT, data_to_plot$within))
  print(cor.test(data_to_plot$BPRS_TOT, data_to_plot$across))
  
  print(ggplot(data = data_to_plot)+
          geom_point(aes(x=XDFR_MRI_ACC_L3,y=within), fill="black")+
          geom_smooth(aes(x=XDFR_MRI_ACC_L3,y=within), method="lm", color="black")+
          geom_point(aes(x=XDFR_MRI_ACC_L3,y=across), color="red")+
          geom_smooth(aes(x=XDFR_MRI_ACC_L3,y=across), method="lm", color="red")+
          ylab("ISC")+
          ggtitle(paste0("network: "), names(network_pairwise)[network]))
  
  print(cor.test(data_to_plot$XDFR_MRI_ACC_L3, data_to_plot$within))
  print(cor.test(data_to_plot$XDFR_MRI_ACC_L3, data_to_plot$across))
  
  
}
## [1] "visual"

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$within
## t = 1.6012, df = 166, p-value = 0.1112
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.02861651  0.26970129
## sample estimates:
##       cor 
## 0.1233276 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$across
## t = 0.65654, df = 166, p-value = 0.5124
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1012987  0.2007545
## sample estimates:
##        cor 
## 0.05089162

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$within
## t = -1.2962, df = 165, p-value = 0.1967
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.24847402  0.05226153
## sample estimates:
##        cor 
## -0.1003989 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$across
## t = -1.062, df = 165, p-value = 0.2898
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.23136068  0.07035191
## sample estimates:
##         cor 
## -0.08239195

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$within
## t = 4.8281, df = 166, p-value = 3.11e-06
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2106881 0.4769721
## sample estimates:
##      cor 
## 0.350904 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$across
## t = 4.3218, df = 166, p-value = 2.659e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1750428 0.4478680
## sample estimates:
##       cor 
## 0.3180239 
## 
## [1] "FPCN"

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$within
## t = 3.5301, df = 166, p-value = 0.0005378
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1175399 0.3996663
## sample estimates:
##       cor 
## 0.2642469 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$across
## t = 0.72207, df = 166, p-value = 0.4713
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.09626941  0.20562368
## sample estimates:
##      cor 
## 0.055956

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$within
## t = -0.23681, df = 165, p-value = 0.8131
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1698207  0.1338057
## sample estimates:
##         cor 
## -0.01843248 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$across
## t = -0.49557, df = 165, p-value = 0.6209
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1893063  0.1139799
## sample estimates:
##         cor 
## -0.03855101

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$within
## t = 1.7854, df = 166, p-value = 0.07602
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.01444652  0.28279595
## sample estimates:
##       cor 
## 0.1372635 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$across
## t = 2.284, df = 166, p-value = 0.02364
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.02376943 0.31756789
## sample estimates:
##      cor 
## 0.174551 
## 
## [1] "DMN"

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$within
## t = 1.3469, df = 166, p-value = 0.1798
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.04819519  0.25142502
## sample estimates:
##       cor 
## 0.1039733 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$across
## t = -0.3589, df = 166, p-value = 0.7201
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1785022  0.1240880
## sample estimates:
##         cor 
## -0.02784499

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$within
## t = -1.2239, df = 165, p-value = 0.2227
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.24321220  0.05784485
## sample estimates:
##         cor 
## -0.09485197 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$across
## t = -1.1393, df = 165, p-value = 0.2562
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.23702809  0.06438283
## sample estimates:
##         cor 
## -0.08834454

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$within
## t = 3.6711, df = 166, p-value = 0.0003253
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1279205 0.4084847
## sample estimates:
##       cor 
## 0.2740229 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$across
## t = 3.9015, df = 166, p-value = 0.0001386
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1447645 0.4226834
## sample estimates:
##       cor 
## 0.2898217 
## 
## [1] "DAN"

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$within
## t = 1.8431, df = 166, p-value = 0.06709
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.01001055  0.28687263
## sample estimates:
##       cor 
## 0.1416139 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$across
## t = 0.34612, df = 166, p-value = 0.7297
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1250638  0.1775424
## sample estimates:
##        cor 
## 0.02685449

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$within
## t = -0.44108, df = 165, p-value = 0.6597
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1852164  0.1181613
## sample estimates:
##        cor 
## -0.0343181 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$across
## t = -0.31544, df = 165, p-value = 0.7528
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1757579  0.1277905
## sample estimates:
##         cor 
## -0.02454957

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$within
## t = 4.4445, df = 166, p-value = 1.605e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1837685 0.4550463
## sample estimates:
##       cor 
## 0.3261046 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$across
## t = 4.2078, df = 166, p-value = 4.212e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1668847 0.4411247
## sample estimates:
##     cor 
## 0.31045 
## 
## [1] "VAN"

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$within
## t = 1.921, df = 166, p-value = 0.05645
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.004034671  0.292347552
## sample estimates:
##       cor 
## 0.1474652 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$across
## t = 0.99438, df = 166, p-value = 0.3215
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.07533739  0.22572996
## sample estimates:
##        cor 
## 0.07695015

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$within
## t = -0.64558, df = 165, p-value = 0.5194
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2005299  0.1024497
## sample estimates:
##         cor 
## -0.05019486 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$across
## t = -0.56907, df = 165, p-value = 0.5701
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1948131  0.1083328
## sample estimates:
##         cor 
## -0.04425894

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$within
## t = 1.9777, df = 166, p-value = 0.04962
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.0003166685 0.2963219344
## sample estimates:
##       cor 
## 0.1517192 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$across
## t = 2.2328, df = 166, p-value = 0.0269
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.01985964 0.31404637
## sample estimates:
##      cor 
## 0.170756

Load Effects

Visualize pairs

network_graphs_load_effect[[1]] 

network_graphs_load_effect[[2]] 

network_graphs_load_effect[[3]] 

network_graphs_load_effect[[4]] 

network_graphs_load_effect[[5]] 

t_test_res = data.frame(matrix(nrow=5,ncol=2)) 
colnames(t_test_res) <- c("t value","p value")
cols <- c("low_within","low_across","med_within","med_across","high_within","high_across")

group_means <- data.frame(matrix(nrow=5,ncol=6))
colnames(group_means) <- cols

group_se <- data.frame(matrix(nrow=5,ncol=6))
colnames(group_se) <- cols

avg_over_groups<- list(mean=data.frame(within = matrix(nrow=5,ncol=1),across = matrix(nrow=5,ncol=1)),
                       se=data.frame(within = matrix(nrow=5,ncol=1),across = matrix(nrow=5,ncol=1)))

split_list <- list()

all_ISC_list_LE <- list()

for (network in seq.int(1:5)){
  
  # define dataframes 
  comps <- data.frame(within = matrix(nrow=170,ncol=1),across = matrix(nrow=170,ncol=1))
  
  split_by_groups <- data.frame(matrix(nrow=56,ncol=6))
  colnames(split_by_groups) <- cols
  
  # loop over all subjects and make comparisons
  for (suj in c(1:56, 58:113, 115:170)){
    if (suj < 57){
      comps$within[suj] <- mean(network_pairwise_span_ordered[[network]][1:56,suj],na.rm=TRUE)
      comps$across[suj] <- mean(network_pairwise_span_ordered[[network]][c(58:113,115:170),suj],na.rm=TRUE)
    }else if (suj > 57 & suj < 114){ 
      comps$within[suj] <- mean(network_pairwise_span_ordered[[network]][58:113,suj],na.rm=TRUE)
      comps$across[suj] <- mean(network_pairwise_span_ordered[[network]][c(1:56,115:170),suj],na.rm=TRUE)
    }else if (suj > 114){ 
      comps$within[suj] <- mean(network_pairwise_span_ordered[[network]][115:170,suj],na.rm=TRUE)
      comps$across[suj] <- mean(network_pairwise_span_ordered[[network]][c(1:56,58:113),suj],na.rm=TRUE)
    }
  }
  
  all_ISC_list_LE[[names(network_pairwise)[network]]] <- comps 
  
  
  # average over groups 
  avg_over_groups[["mean"]]$within[network] <- mean(comps$within, na.rm=TRUE)
  avg_over_groups[["mean"]]$across[network] <- mean(comps$across, na.rm=TRUE)
  avg_over_groups[["se"]]$within[network] <- se(comps$within)
  avg_over_groups[["se"]]$across[network] <- se(comps$across)
  
  avg_over_groups[["mean"]]$difference[network] <- avg_over_groups[["mean"]]$within[network] - avg_over_groups[["mean"]]$across[network]
  avg_over_groups[["se"]]$difference[network] <- se(comps$within - comps$across)
  
  # split by groups 
  split_by_groups$low_across <- comps$across[1:56]
  split_by_groups$low_within <- comps$within[1:56]
  
  split_by_groups$med_across <- comps$across[58:113]
  split_by_groups$med_within <- comps$within[58:113]
  
  split_by_groups$high_across <- comps$across[115:170]
  split_by_groups$high_within <- comps$within[115:170]
  
  split_list[[names(network_pairwise)[network]]] <- split_by_groups
  
  group_means[network,] <- colMeans(split_by_groups)
  for (group in seq.int(1,6)){
    group_se[network,group] <- se(split_by_groups[,group])
  }
  temp2 <- t.test(comps$within,comps$across,paired=TRUE,var.equal = FALSE)
  t_test_res[network,] <- c(temp2$statistic,temp2$p.value)
  
}

rownames(t_test_res) <- names(network_pairwise) 
print(t_test_res)
##           t value     p value
## visual -1.0877393 0.278277558
## FPCN    3.3130726 0.001131379
## DMN     1.1234601 0.262854555
## DAN    -0.8727005 0.384079386
## VAN     1.6959284 0.091762824

Compare across groups

bar_list <- list()
bar_plot_data <- data.frame(matrix(nrow = 30, ncol=7))
colnames(bar_plot_data) <- c("mean", "se", "network_name", "comparison", "WMC", "err_min", "err_max")
comparison_list <- c("within", "across")
WMC_list <- c("low", "med", "high")
row_count=1
#row for mean, se, network, comparison, WMC
for (network in seq.int(1,5)){
  for (WMC in seq.int(1,3)){
    for (comparison in seq.int(1,2)){
      col_to_look <- ((WMC-1)*2+1) + (comparison-1)
      bar_plot_data$mean[row_count] <- mean(split_list[[network]][,col_to_look])  
      bar_plot_data$se[row_count] <- group_se[network,col_to_look]
      bar_plot_data$err_min[row_count] <- bar_plot_data$mean[row_count] - bar_plot_data$se[row_count]
      bar_plot_data$err_max[row_count] <- bar_plot_data$mean[row_count] + bar_plot_data$se[row_count]
      bar_plot_data$network_name[row_count] <- names(network_pairwise)[network]
      bar_plot_data$comparison[row_count] <- comparison_list[comparison] 
      bar_plot_data$WMC[row_count] <- WMC_list[WMC]
      row_count = row_count+1
    }
  }
  
  bar_plot_data$comparison <- as.factor(bar_plot_data$comparison)
  bar_plot_data$WMC <- factor(bar_plot_data$WMC, levels=c("low", "med", "high"))
  
  bar_plot_data %>%
    filter(network_name == names(network_pairwise)[network]) %>%
    ggplot(aes(x=WMC, y= mean, fill=comparison))+
    geom_bar(stat="identity", position="dodge")+
    geom_errorbar(aes(ymin=err_min, ymax=err_max), position=position_dodge(0.9), width=0.2)+
    ylab("Mean ISC")+
    ggtitle(paste0("network:", names(network_pairwise)[network])) -> bar_list[[names(network_pairwise)[network]]]
  
  
}
(bar_list[["visual"]] + bar_list[["FPCN"]]) +
  plot_layout(guides="collect")

(bar_list[["DMN"]]+ bar_list[["DAN"]])+
  plot_layout(guides="collect")

bar_list[["VAN"]] 

Relate to behavior

visual with acc within FPCN with span/within DMN with acc within and across DAN with span withi; with acc both; both with BPRS if outlier removed VAN within with span

for (network in seq.int(1,5)){
  data_to_plot <- data.frame(constructs_fMRI[span_order, c(1,7)], all_ISC_list_LE[[network]])
  data_to_plot <- merge(data_to_plot, p200_clinical_zscores[,c(1,2,8)], by="PTID")
  data_to_plot <- merge(data_to_plot, p200_data[,c(1,7)], by="PTID")
  data_to_plot$BPRS_TOT[data_to_plot$BPRS_TOT > 4] <- NA
  
  print(names(network_pairwise)[network])
  
  print(ggplot(data = data_to_plot)+
          geom_point(aes(x=omnibus_span_no_DFR_MRI,y=within), fill="black")+
          geom_smooth(aes(x=omnibus_span_no_DFR_MRI,y=within), method="lm", color="black")+
          geom_point(aes(x=omnibus_span_no_DFR_MRI,y=across), color="red")+
          geom_smooth(aes(x=omnibus_span_no_DFR_MRI,y=across), method="lm", color="red")+
          ylab("ISC")+
          ggtitle(paste0("network: "), names(network_pairwise)[network]))
  
  print(cor.test(data_to_plot$omnibus_span_no_DFR_MRI, data_to_plot$within))
  print(cor.test(data_to_plot$omnibus_span_no_DFR_MRI, data_to_plot$across))
  
  
  print(ggplot(data = data_to_plot)+
          geom_point(aes(x=BPRS_TOT,y=within), fill="black")+
          geom_smooth(aes(x=BPRS_TOT,y=within), method="lm", color="black")+
          geom_point(aes(x=BPRS_TOT,y=across), color="red")+
          geom_smooth(aes(x=BPRS_TOT,y=across), method="lm", color="red")+
          ylab("ISC")+
          ggtitle(paste0("network: "), names(network_pairwise)[network]))
  
  print(cor.test(data_to_plot$BPRS_TOT, data_to_plot$within))
  print(cor.test(data_to_plot$BPRS_TOT, data_to_plot$across))
  
  print(ggplot(data = data_to_plot)+
          geom_point(aes(x=XDFR_MRI_ACC_L3,y=within), fill="black")+
          geom_smooth(aes(x=XDFR_MRI_ACC_L3,y=within), method="lm", color="black")+
          geom_point(aes(x=XDFR_MRI_ACC_L3,y=across), color="red")+
          geom_smooth(aes(x=XDFR_MRI_ACC_L3,y=across), method="lm", color="red")+
          ylab("ISC")+
          ggtitle(paste0("network: "), names(network_pairwise)[network]))
  
  print(cor.test(data_to_plot$XDFR_MRI_ACC_L3, data_to_plot$within))
  print(cor.test(data_to_plot$XDFR_MRI_ACC_L3, data_to_plot$across))
  
  
}
## [1] "visual"

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$within
## t = 0.72347, df = 166, p-value = 0.4704
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.09616224  0.20572728
## sample estimates:
##        cor 
## 0.05606383 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$across
## t = 0.077256, df = 166, p-value = 0.9385
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1455458  0.1572631
## sample estimates:
##         cor 
## 0.005996103

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$within
## t = -1.2377, df = 165, p-value = 0.2176
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.24421648  0.05678066
## sample estimates:
##         cor 
## -0.09590996 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$across
## t = -1.2493, df = 165, p-value = 0.2133
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.24506491  0.05588109
## sample estimates:
##         cor 
## -0.09680401

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$within
## t = 2.2592, df = 166, p-value = 0.02517
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.02187271 0.31586054
## sample estimates:
##       cor 
## 0.1727105 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$across
## t = 1.6242, df = 166, p-value = 0.1062
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.02684343  0.27134588
## sample estimates:
##       cor 
## 0.1250747 
## 
## [1] "FPCN"

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$within
## t = 2.5448, df = 166, p-value = 0.01184
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.04364479 0.33534507
## sample estimates:
##       cor 
## 0.1937741 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$across
## t = 0.57111, df = 166, p-value = 0.5687
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1078495  0.1943898
## sample estimates:
##        cor 
## 0.04428339

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$within
## t = -1.3264, df = 165, p-value = 0.1866
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.25066394  0.04993225
## sample estimates:
##        cor 
## -0.1027102 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$across
## t = -1.7045, df = 165, p-value = 0.09017
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.27785354  0.02073744
## sample estimates:
##        cor 
## -0.1315404

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$within
## t = 1.0952, df = 166, p-value = 0.275
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.06757768  0.23311896
## sample estimates:
##        cor 
## 0.08469874 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$across
## t = 1.1392, df = 166, p-value = 0.2563
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.06419362  0.23633052
## sample estimates:
##        cor 
## 0.08807219 
## 
## [1] "DMN"

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$within
## t = 1.4721, df = 166, p-value = 0.1429
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.0385545  0.2604512
## sample estimates:
##      cor 
## 0.113518 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$across
## t = 0.083877, df = 166, p-value = 0.9333
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1450427  0.1577643
## sample estimates:
##         cor 
## 0.006510009

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$within
## t = 0.32537, df = 165, p-value = 0.7453
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1270299  0.1765070
## sample estimates:
##        cor 
## 0.02532216 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$across
## t = -0.53845, df = 165, p-value = 0.591
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1925209  0.1106858
## sample estimates:
##         cor 
## -0.04188179

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$within
## t = 2.1863, df = 166, p-value = 0.03019
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.0163018 0.3108348
## sample estimates:
##       cor 
## 0.1672987 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$across
## t = 2.3111, df = 166, p-value = 0.02206
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.02583945 0.31942908
## sample estimates:
##       cor 
## 0.1765585 
## 
## [1] "DAN"

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$within
## t = 2.7707, df = 166, p-value = 0.006232
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.06076595 0.35049405
## sample estimates:
##       cor 
## 0.2102414 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$across
## t = 0.51, df = 166, p-value = 0.6107
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1125307  0.1898260
## sample estimates:
##        cor 
## 0.03955304

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$within
## t = -1.9661, df = 165, p-value = 0.05097
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2963526368  0.0005786435
## sample estimates:
##        cor 
## -0.1512982 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$across
## t = -2.1547, df = 165, p-value = 0.03264
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.30951640 -0.01391464
## sample estimates:
##        cor 
## -0.1654287

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$within
## t = 3.3413, df = 166, p-value = 0.00103
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1035562 0.3877038
## sample estimates:
##     cor 
## 0.25103 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$across
## t = 2.4909, df = 166, p-value = 0.01373
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.03954032 0.33169084
## sample estimates:
##       cor 
## 0.1898137 
## 
## [1] "VAN"

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$within
## t = 2.4846, df = 166, p-value = 0.01396
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.03906592 0.33126791
## sample estimates:
##       cor 
## 0.1893557 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span_no_DFR_MRI and data_to_plot$across
## t = 0.95383, df = 166, p-value = 0.3416
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.07845706  0.22274954
## sample estimates:
##        cor 
## 0.07382977

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$within
## t = -1.6117, df = 165, p-value = 0.1089
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2712288  0.0278980
## sample estimates:
##       cor 
## -0.124493 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$BPRS_TOT and data_to_plot$across
## t = -1.6854, df = 165, p-value = 0.09379
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.27649686  0.02220636
## sample estimates:
##       cor 
## -0.130096

## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$within
## t = 0.44308, df = 166, p-value = 0.6583
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1176528  0.1848173
## sample estimates:
##        cor 
## 0.03436926 
## 
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$XDFR_MRI_ACC_L3 and data_to_plot$across
## t = 0.4127, df = 166, p-value = 0.6804
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1199763  0.1825400
## sample estimates:
##       cor 
## 0.0320151

Spatial ISC